const Controller = require('../../core/controller/ApiController');
const {Route, HttpGet, HttpPost, Middleware, filters} = require('../../../plugin/egg-decorator-router/lib');
const {ExceptionHandler} = require('../../../plugin/egg-controller-exception-handler/lib');

@Route('/api/mobile/service')
class ServiceController extends Controller {

    //获取服务项目列表
    @HttpGet('/item/list')
    @ExceptionHandler()
    async getAllServiceItem() {
        this.result.data = await this.service.mobile.service.main.getAllServiceItem();
    }

    //开始服务
    @HttpPost('/start')
    @ExceptionHandler()
    async startService() {
        const rule = {
            aged_id: 'int',
            status: 'int'
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        await this.service.mobile.service.main.startService(body.aged_id, body.status);
    }

    //提交服务
    @HttpPost('/commit')
    @ExceptionHandler()
    async commitService() {
        const rule = {
            aged_id: 'int',
            score: 'number',
            text_evalu: 'string',
            voice_evalu: 'string',
            svc_item_list: {type: 'array', itemType: 'int', rule: 'int'},
        };
        const body = this.ctx.request.body;
        this.validate(rule, body);
        await this.service.mobile.service.main.commitService(body);
    }

    @HttpGet('/record')
    @ExceptionHandler()
    async getMonthSvcRecords() {
        const rule = {
            year: 'int',
            month: 'int',
            pn: 'int',
            ps: 'int'
        };
        const query = this.ctx.request.query;
        this.validate(rule, query);
        this.result.data = await this.service.mobile.service.main.getMonthSvcRecords(query.year, query.month, query.pn, query.ps);
    }
}

module.exports = ServiceController;
